﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MarginTrading.Entity;
using MarginTrading.Common;
using MarginTrading.Services;

namespace MarginTrading.Forms
{
    public partial class MainWnd : Form
    {
        public MainWnd()
        {
            InitializeComponent();
        }

        private void MainWnd_Load(object sender, EventArgs e)
        {
            try
            {
                Config config = ConfigServices.GetConfigByName(Constants.CONFIG_NAME_COMPANY_NAME);
                Text = config.Value + " - Margin Trading System";
            }
            catch (System.Exception ex)
            {
                Text = "Margin Trading System";
            }
            if (Program.currentUser.UserType != 1)
            {
                dailyInterestStatementToolStripMenuItem.Visible = false;
                manageMenuItem.Visible = false;
                manuallyToolStripMenuItem.Visible = false;
                unSettleToolStripMenuItem.Visible = false;
                portfolioToolStripMenuItem.Visible = false;
            }
        }

        private void AddUser_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new AddUser());
        }

        private void EditUser_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new EditUser());
        }

        private void RemoveUser_Click(object sender, EventArgs e)
        {

        }

        private void AllUsers_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AllUsers());
        }

        private void AddClient_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new AddClient());
        }

        private void EditClient_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new EditClient());
        }

        private void RemoveClient_Click(object sender, EventArgs e)
        {

        }

        private void AllClients_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AllClients());
        }

        private void AddAdvisor_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new AddAdvisor());
        }

        private void EditAdvisor_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new EditAdvisor());
        }

        private void RemoveAdvisor_Click(object sender, EventArgs e)
        {

        }

        private void AllAdvisors_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AllAdvisors());
        }

        private void AddAgent_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new AddAgent());
        }

        private void EditAgent_Click(object sender, EventArgs e)
        {
            ShowDialogBox(new EditAgent());
        }

        private void RemoveAgent_Click(object sender, EventArgs e)
        {

        }

        private void AllAgents_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AllAgents());
        }

        private void paymentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Transaction oCreditReceiptForm = new Transaction();
            oCreditReceiptForm.ShowDialog();
        }

        private void accountStatementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AccountStatement());
        }

        private void portfolioStatementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new PortfolioValuation());
        }

        private void dailyTradesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new TradesWnd());
        }

        private void portfolioTableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new PortfolioTable());
        }

        private void addSecurityToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddSecurity oAddSecurityDlg = new AddSecurity();
            oAddSecurityDlg.ShowDialog();
        }

        private void editSecurityToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EditSecurity oEditSecurityDlg = new EditSecurity();
            oEditSecurityDlg.ShowDialog();
        }

        private void viewAllSecuritiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AllSecurities());
        }

        private void quickAddClientsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            QuickAddClients oQuickAddClientsWnd = new QuickAddClients();
            oQuickAddClientsWnd.ShowDialog();
        }

        private void configurationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConfigsDlg oConfigsDlg = new ConfigsDlg();
            oConfigsDlg.ShowDialog();
        }

        private void manuallyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddTrade oAddTradeDlg = new AddTrade();
            oAddTradeDlg.ShowDialog();
        }

        private void settlementsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new SettlementsWnd());
        }

        private void debtorsFollowupToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new DebtorsFollowup());
        }

        private void statusToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new MarginTradingStatus());
        }

        private void interestStatementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new InterestStatement());
        }

        private void clientsLoanAccountToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new ClientsLoanAccount());
        }

        private void dataUploadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new HQDataLoading());
        }

        private void agToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new AgentDataLoading());
        }

        private void dailyIntersetCalculationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new DailyIntersetCal());
        }

        private void monthlyInterestPostingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new MonthlyInterest());
        }

        private void settleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new SettlementsWnd());
        }

        private void unSettleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new UnsettleWnd());
        }

        private void holidaysToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new Holidays());
        }

        private void ShowMDIChild(Form form)
        {
            form.MdiParent = this;
            form.Show();

            //workaround to show the icon
            ActivateMdiChild(null);
            ActivateMdiChild(form);
        }

        private void ShowDialogBox(Form form)
        {
            form.ShowDialog();
        }

        private void toolStripButtonStatementOfAccount_Click(object sender, EventArgs e)
        {
            accountStatementToolStripMenuItem_Click(null, null);
        }

        private void toolStripButtonPortfolio_Click(object sender, EventArgs e)
        {
            portfolioStatementToolStripMenuItem_Click(null, null);
        }

        private void toolStripButtonDebtors_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new BuySettlementSummary());
            //debtorsFollowupToolStripMenuItem_Click(null, null);
        }

        private void toolStripButtonMarginLimit_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new SellSettlementSummary());
            //statusToolStripMenuItem_Click(null, null);
        }

        private void toolStripButtonDailyInterest_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new MarginTradingStatus());
            //interestStatementToolStripMenuItem_Click(null, null);
        }

        private void toolStripButtonLoanAccount_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new SettlementsWnd());
            //clientsLoanAccountToolStripMenuItem_Click(null, null);
        }

        private void buySettlementSummaryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new BuySettlementSummary());
        }

        private void buySettlementSummaryToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new SellSettlementSummary());
        }

        private void initialSettlementsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new InitialSettlements());
        }

        private void portfolioToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new InitialPortfolios());
        }

        private void clientsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new InitialPortfolios());
        }

        private void dailyInterestStatementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new InterestStatement());
        }

        private void portfolioUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new CDSPortfolio());
        }

        private void bOIntegrationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowMDIChild(new BO_Integration());
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

